package com.longjianghuasheng.logistics.business.advisory

import androidx.collection.arrayMapOf
import androidx.lifecycle.MutableLiveData
import com.longjianghuasheng.logistics.R
import com.longjianghuasheng.logistics.base.BaseMultiStateViewModel
import com.longjianghuasheng.logistics.data.model.bean.ApiResponseNoData
import com.longjianghuasheng.logistics.ext.commit2
import com.longjianghuasheng.logistics.ext.judge
import com.longjianghuasheng.logistics.ext.toastNormal
import com.longjianghuasheng.logistics.network.apiService

class AskForAQuotationViewModel : BaseMultiStateViewModel() {
    val result by lazy {
        MutableLiveData<ApiResponseNoData>()
    }


    var names = ""


    var start_address = ""

    var end_address = ""


    var types = ""

    var weights = ""
    var volume = ""
    var get_type = 1

    val arrayMap by lazy {

        arrayMapOf(
            R.id.rb_land_transportation to 1
        )
    }

    var sent_type = mutableListOf<Int>()

    var place_type = 2


    fun service_form() {

        var isSuccess = false
        when {

            start_address.judge("请输入起始地") -> {}
            end_address.judge("请输入目的地") -> {}
            names.judge("请输入货物名称") -> {}
            types.judge("请输入种类") -> {}
            weights.judge("请输入重量") -> {}
            volume.judge("请输入体积") -> {}
            sent_type.isEmpty() -> toastNormal("请选择运输方式")


            else -> isSuccess = true
        }

        if (!isSuccess) return



        commit2({
            apiService.service_form(
                hashMapOf(
                    "start_address" to start_address,
                    "end_address" to end_address,
                    "names" to names,
                    "types" to types,
                    "weights" to weights,
                    "volume" to volume,
                    "get_type" to get_type.toString(),
                    "sent_type[]" to sent_type.joinToString (","){ it.toString() },
                    "place_type" to place_type.toString(),
                )
            )
        }, result)
    }
}